# python -m project_root.api.api_alarmset
from .api_token import Token
import requests

class Api_AlarmSet(Token):


    def get_device_alarm(self):
        url = 'http://hxzhan.rtcloud.com:32111/tm/alarm/device_alarm_status/get'
        json = {
            'device_id':57714
        }
        response = requests.post(url=url,json=json,headers=self.get_header())
        values = []
        data = response.json()['data']['status']
        if data == 1:
            return '开启'
        elif data == 2:
            return '关闭'

    def get_alarmsetlist(self,type='info'):
        url = 'http://hxzhan.rtcloud.com:32111/tm/alarm/config/get'
        json = {
            'device_id':57714
        }
        response = requests.post(url=url,json=json,headers=self.get_header())
        data = response.json()['data']
        if type == 'info':
            keys = ['i_limit','ii_limit','ws_val']
            info_values = []
            for key in keys:
                info_values.append(data['info'][key])
            return info_values
        elif  type == 'mps':
            keys = ['i_status','ii_status','ws_status']
            mps_values = []
            for elm in data['mps']:
                if 'Temp' in elm['key']:
                    for key in keys:
                        if elm[key] == 1:
                            mps_values.append('启用')
                        elif elm[key] == 2:
                            mps_values.append('禁用')
            return mps_values




# ap = Api_AlarmSet()
# print(ap.get_alarmsetlist(type='info'))